using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace WPCoco.Tasks
{
    public class EaseElasticInOutFunction : EaseFunction
    {
        public EaseElasticInOutFunction(float period)
        {
            if (Math.Abs(period) < float.Epsilon) period = (0.3f * 1.5f);
            this.period = period;
        }

        readonly float period;

        public override float Evaluate(float time)
        {
            float result = 0;

            if (time <= 0 || time >= 1)
            {
                result = time;
            }
            else
            {
                time = time * 2;
            
                float s = period / 4;

                time = time - 1;
                if (time < 0)
                {
                    result = (float)(-0.5f * Math.Pow(2, 10 * time) * Math.Sin((time - s) * MathHelper.TwoPi / period));
                }
                else
                {
                    result = (float)(Math.Pow(2, -10 * time) * Math.Sin((time - s) * MathHelper.TwoPi / period) * 0.5f + 1);
                }
            }
            return result;
        }
    }
}
